﻿using System.Collections.Generic;
namespace SDi.Login.Model
{
    public class User : DynamicModel
    {
        #region Fields
        private int _idUser;
        private string _name;
        private string _email;
        private string _password;
        private bool _activated;
        #endregion

        #region Constructors
        public User(int idUser = -1, string name = null, string email = null, string password = null, bool activated = false)
            : base("[dbo].[USER]", "IdUser")
        {
            IdUser = idUser;
            Name = name;
            Email = email;
            Password = password;
            Activated = activated;
        }
        #endregion

        #region Properties
        public int IdUser
        {
            get { return _idUser; }
            set {
                if (value >= 0)
                {
                    _idUser = value;
                    var table = new Capability();
                    //var capatibilities = table.All(columns:"IdCapatibility AS IdCapatibility, Code AS Code, Name AS Name", where: "WHERE idUser = @0", args: value);
                    //var capatibilities = table.Find(IdUser: this.IdUser);
                    var capatibilities = table.All<Capability>(columns:"IdCapability AS IdCapability, Code AS Code, Name AS Name", where: "WHERE idUser = @0", args: value);
                  

                    Capability cap = System.Convert.ChangeType((capatibilities as IEnumerator<dynamic>).Current, typeof(Capability));
                } 
            }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public bool Activated
        {
            get
            {
                return this._activated;
            }
            set
            {
                this._activated = value;
            }
        }

        private List<Capability> _capabilities;

        public List<Capability> Capabilities
        {
            get { return _capabilities; }
            set { _capabilities = value; }
        }

        #endregion


    }
}
